package 力扣._00周赛._367周赛.问题3;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution {
    class t {
        int i;
        int val;

        public t(int i, int num) {
            this.i = i;
            this.val = num;
        }
    }

    public int[] findIndices(int[] nums, int indexDifference, int valueDifference) {
        //
        List<t> list = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            list.add(new t(i, nums[i]));
        }
        list.sort((o1, o2) -> o1.val - o2.val);
        for (int i = 0; i < nums.length; i++) {
            for (int j = nums.length-1; j >= 0; j--) {
                if (list.get(j).val - list.get(i).val >= valueDifference) {
                    if (Math.abs(list.get(j).i - list.get(i).i) >= indexDifference)
                        return new int[]{list.get(j).i, list.get(i).i};
                } else
                    break;
            }
        }
        return new int[]{-1, -1};
    }

    public static void main(String[] args) {
        int[] indices = new Solution().findIndices(new int[]{5, 1, 4, 1}, 2, 4);
        System.out.println(Arrays.toString(indices));
    }
}

